using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for processDeliveryType
/// </summary>
public class processDeliveryType:DBConnectionTool
{
	public processDeliveryType():base()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public string getDeliveryTypeID()
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("select right(max(DeliveryTypeID),2) from DeliveryTypes", cn);
        String s = cmd.ExecuteScalar().ToString();
        Int32 result;
        if (Int32.TryParse(s, out result))
            result++;
        else
            result = 1;
        int l = result.ToString().Length;
        int count = 2 - l;
        string sresult = "PaT";
        for (int i = 0; i < count; i++)
        {
            sresult = sresult + "0";
        }
        sresult = sresult + result;
        CloseCn();
        return sresult;
    }
    public DataTable getDeliveryType()
    {
        OpenCn();
        SqlDataAdapter da = new SqlDataAdapter("Select * from DeliveryTypes", cn);
        DataTable dt = new DataTable("DeliveryTypes");
        da.Fill(dt);
        CloseCn();
        return dt;
    }
    public int insertDeliveryType(string DeliveryTypeID, string DeliveryTypeName)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Insert Into DeliveryTypes(DeliveryTypeID,DeliveryTypeName) Values(@DeliveryTypeID,@DeliveryTypeName)", cn);
        cmd.Parameters.Add(new SqlParameter("@DeliveryTypeID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@DeliveryTypeName", SqlDbType.NVarChar, 200));
        cmd.Parameters["@DeliveryTypeID"].Value = DeliveryTypeID;
        cmd.Parameters["@DeliveryTypeName"].Value = DeliveryTypeName;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
    public int updateDeliveryType(string DeliveryTypeID, string DeliveryTypeName)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("update DeliveryTypes set DeliveryTypeName=@DeliveryTypeName where DeliveryTypeID=@DeliveryTypeID", cn);
        cmd.Parameters.Add(new SqlParameter("@DeliveryTypeID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@DeliveryTypeName", SqlDbType.NVarChar, 200));
        cmd.Parameters["@DeliveryTypeID"].Value = DeliveryTypeID;
        cmd.Parameters["@DeliveryTypeName"].Value = DeliveryTypeName;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    public int deleteDeliveryType(string DeliveryTypeID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Delete DeliveryTypes Where DeliveryTypeID ='" + DeliveryTypeID + "'", cn);
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
}
